package com.platform.qujia.controller;

import com.platform.qujia.pojo.PayOrder;
import com.platform.qujia.pojo.RchReductionReq;
import com.platform.qujia.pojo.ReductionActivityBalanceRecord;
import com.platform.qujia.service.ReductionActivityBalanceRecordService;
import com.platform.qujia.service.ReductionActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("reductionActivity")
@Api(tags = "立减活动")
public class ReductionActivityController {
    @Autowired
    private ReductionActivityBalanceRecordService reductionActivityBalanceRecordService;
    @Autowired
    private ReductionActivityService reductionActivityService;


    @ApiOperation(value = "充值立减活动", httpMethod = "POST", notes = "充值立减活动")
    @PostMapping(value = "/createActivityBalanceRecord", produces = "application/json;charset=UTF-8")
    public ResponseEntity createActivityBalanceRecord(@RequestBody ReductionActivityBalanceRecord record){
        Integer result = reductionActivityBalanceRecordService.createBalanceRecord(record.getRechargeAmt(), record.getPhysicalCardNo(), record.getEnterpriseId(), record.getPaymentMethod(),record.getStationId());
        return ResponseEntity.ok(result);
    }
    @ApiOperation(value = "充值立减金额", httpMethod = "POST", notes = "充值立减金额")
    @PostMapping(value = "/getRchReductionAmt", produces = "application/json;charset=UTF-8")
    public ResponseEntity getRchReductionAmt(@RequestBody  RchReductionReq req){
        Map<String, Object> rchReductionAmt = reductionActivityService.getRCHReductionAmt(req.getPhysicalCardNo(), req.getAmt(), req.getStationId(), req.getOilId(), req.getOrderLiters());
        return ResponseEntity.ok(rchReductionAmt);
    }

    @ApiOperation(value = "充值立减金额", httpMethod = "POST", notes = "充值立减金额")
    @PostMapping(value = "/updateBalance", produces = "application/json;charset=UTF-8")
    public ResponseEntity updateBalance(@RequestBody  RchReductionReq req){
        reductionActivityBalanceRecordService.updateBalance(req.getAmt(),req.getRCHReductionAmt(),req.getPhysicalCardNo());
        return ResponseEntity.ok("success");
    }
}
